package chances.epg.api.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class CustomAccessController {
	public static final String CUSTOM_API_PACKAGE = "/api";
	

	@RequestMapping(value = "/custom/{method}") 
    public String getVod (@PathVariable String method,ModelMap model, HttpServletRequest request,HttpServletResponse response) throws IOException {
	    String templateFile = method + ".jsp";
	    String templatePath = this.getTemplatePath(templateFile);
		return templatePath;
	}
	
	private String getTemplatePath(String templatePath) {
		
		
		String templatePackagePath =  CUSTOM_API_PACKAGE;
		if(StringUtils.isNotBlank(templatePath)){
			if(templatePath.startsWith("/")){
				return templatePackagePath + templatePath;
			}else{
				return templatePackagePath + "/" + templatePath;
			}
		}else{
		    return templatePackagePath;
		}
	}
}
